<template>
  <div class="login_container">
    <div class="login_wrapper">
     <div class="login-logo">
       <img src="../../public/images/dt1 (1).jpg" 
       style="width:40px;height:40px;border-radius:50%;
       margin-top:-100px;">
       </div>
      
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="0px"
      >
        <el-form-item prop="name" label-width="0">
          <el-input
            v-model="ruleForm.name"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password" label-width="0">
          <el-input
          type="password"
            v-model="ruleForm.password"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item label-width="0">
          <el-button type="primary" @click="onClickLogin('ruleForm')"
            >立即登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        password: "",
      },
      rules: {
        name: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  mounted() {},
  methods: {
    onClickLogin(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm.name);
          console.log(this.ruleForm.password);
          this.$axios
            .post("https://www.liulongbin.top:8888/api/private/v1/login", {
              username: this.ruleForm.name,
              password: this.ruleForm.password,
            })
            .then((res) => {
              var token = res.data.data.token;
              localStorage.setItem("token", token);
              this.$router.push("/");
              this.$message("登录成功");
            });
        } else {
          this.$message("登录失败");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.login_container {
  width: 100%;
  height: 100vh;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: lightblue;
  .login_wrapper {
    width: 30%;
    height: 45vh;
    // border: 1px solid lightgray;
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    .login-logn{
      width: 100%;
      height: 60px;
      border:1px solid black;
      margin-top: 20px;
    }
    .login_button {
      width: 100%;
      height: 40px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border: none;
      outline: none;
      background: #008080;
      color: white;
      border-radius: 8px;
    }
  }
}
.el-button{
    width: 100%;
}
</style>